package glemipsc.instructions;

import glemipsc.Address;
import glemipsc.Function;
import glemipsc.GLEMipsC;
import glemipsc.Type;
import glemipsc.implementations.Argument;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


public class Case extends BaseInstruction implements Serializable, Instruction, Expression {
	private int Const;
	private ArrayList Instructions = null;
	private Address addr;
	private boolean defaultCase = true; // Se true siamo nel case di default
	private Address storeAddress;
	
	public Case(Expression constant, ArrayList Instructions){
		this.defaultCase = false;
		this.Const = constant.getImmediateValue();
		this.Instructions = Instructions;
		Iterator iter = Instructions.iterator();
		while (iter.hasNext()) {
			Instruction instr = (Instruction) iter.next();
			instr.setParent(this);
		}
	}
	public Case(ArrayList Instructions){
		this.Instructions = Instructions;
		Iterator iter = Instructions.iterator();
		while (iter.hasNext()) {
			Instruction instr = (Instruction) iter.next();
			instr.setParent(this);
		}
	}
	@Override
	public void computeInstruction(Argument result,
			List<glemipsc.implementations.Instruction> instructions,
			Function func) {
		Iterator iter = Instructions.iterator();
		while (iter.hasNext()) {
			Instruction instr = (Instruction) iter.next();
			instr.computeInstruction(result, instructions, func);
		}
	}

	@Override
	public int getNumberOfOperands() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Expression getOperand(int index) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int getImmediateValue() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Address getStoreAddress() {
		return storeAddress;
	}

	@Override
	public int getStoredSize() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Type getType() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean isImmediate() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isStored() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void setStoreAddress(Address addr) {
		this.storeAddress = addr;
	}
	
	public boolean isDefaultCase() {
		return this.defaultCase;
	}
	
	public int getConst() {
		return Const;
	}

}
